import sqlalchemy as sa
from sqlalchemy import orm

from wiki.model import meta

def init_model(engine):
    """Call me before using any of the tables or classes in the model."""

    sm = orm.sessionmaker(autoflush=True, transactional=True, bind=engine)

    meta.engine = engine
    meta.Session = orm.scoped_session(sm)

t_dictionary = sa.Table("Dictionary", meta.metadata,
    sa.Column("id", sa.types.Integer, primary_key=True),
    sa.Column("term", sa.types.String(100), nullable=False),
    sa.Column("definition", sa.types.String, nullable=False),
    )

class Dictionary(object):
    pass

orm.mapper(Dictionary, t_dictionary)
